#pragma once
#include<iostream>
#include<assert.h>
#include<string>
using namespace std;


namespace zhaojiahao
{
	class string
	{
	public:
		typedef char* iterator;
		typedef const char* const_iterator;
		iterator begin()
		{
			return _str;
		}
		iterator end()
		{
			return _str + _size;
		}

		const_iterator begin() const
		{
			return _str;
		}
		const_iterator end() const
		{
			return _str + _size;
		}

		int size()
		{
			return _size;
		}
		int capacity()
		{
			return _capacity;
		}
		const char* c_str() const
		{
			return _str;
		}
		string(const char* str="")
		{
			int len = strlen(str);
			_size = len;
			_capacity = len;
			_str = new char[_capacity + 1];
			strcpy(_str, str);
		}
		~string()
		{
			_size = _capacity=0;
			delete[] _str;
			_str = nullptr;
		}

		void clear()
		{
			_size = 0;
			_str[0] = '\0';
		}

		char& operator[](size_t pos)
		{
			assert(pos < _size);

			return _str[pos];
		}
		const char& operator[](size_t pos) const//const 
		{
			assert(pos < _size);

			return _str[pos];
		}

		void reserve(size_t n);
		void push_back(char ch);
		void append(const char* str);
		string& operator+=(char ch);
		string& operator+=(const char* str);

		void insert(size_t pos, char ch);
		void insert(size_t pos, const char* str);

	private:
		char* _str=nullptr;
		int _size = 0;
		int _capacity = 0;
	};
}